#ifndef __LOG_HPP__
#define __LOG_HPP__

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <time.h>

#define NORMAL  0
#define WARNING 1
#define ERROR   2
#define FATAL   3

const char* str[]={
    "NORMAL",
    "WARNING",
    "ERROR",
    "FATAL"
};

void logMessage(int level,const char* format,...)
{
    //标准日志
    char stdBuff[64];
    memset(stdBuff,0,sizeof(stdBuff));
    time_t tm=time(nullptr);
    snprintf(stdBuff,sizeof(stdBuff),"[%s][%d]",str[level],tm);

    //自定义日志
    char logBuff[64];
    memset(logBuff,0,sizeof(logBuff));
    va_list ap;
    va_start(ap,format);
    vsnprintf(logBuff,sizeof(logBuff),format,ap);
    va_end(ap);

    //控制输出
#ifdef PRINT
    printf("%s%s",stdBuff,logBuff);
#else
    FILE* fp=fopen("./UDP.log","w");
    fprintf(fp,"%s%s",stdBuff,logBuff);
    fclose(fp);
#endif
}

#endif